package com.itany.corejava.day12;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestRobot {

    private JFrame jf;
    private JTextArea jta;

    public TestRobot() {

        jf=new JFrame();
        jta=new JTextArea(20,40);
    }

    private void init(){
        jf.add(jta);
    }

    private void addEventHandler(){
        jta.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e)  {

                try {

                    if(KeyEvent.VK_A==e.getKeyCode()){
                        Robot robot=new Robot();


//                        robot.mouseMove(0,0);

                        for (int i = 0; i < 10; i++) {
                            robot.keyPress(KeyEvent.VK_B);
                        }






                    }






                } catch (Exception ex) {
                    ex.printStackTrace();
                }


            }
        });
    }

    public void show(){
        init();
        addEventHandler();
        jf.pack();
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new TestRobot().show();
    }
}
